unit u_sound;

interface
{$O-}
uses
  system.Windows.forms,
  Microsoft.DirectX,
  Microsoft.DirectX.DirectSound,
 Microsoft.DirectX.AudioVideoPlayback;

type

c_sound = Class
  private
    son : Audio;
    Dsbuffer : SecondaryBuffer;
    sound_dev : Device;
    actif : boolean;
  public
    constructor create(f_name : string);
    procedure play;
    procedure stop;
    procedure dispose;
    procedure entendre(_bool : boolean);
end;

implementation

constructor c_sound.create(f_name : string);
var
  formcontrl : Control;
  begin
    inherited create;
    actif := true;
    formcontrl := Control.Create;
    sound_dev := Device.Create;
    sound_dev.SetCooperativeLevel(formcontrl, CooperativeLevel.Normal);
    Dsbuffer := SecondaryBuffer.Create(f_name, sound_dev);
  end;

procedure c_sound.play;
  begin
    if actif then
      Dsbuffer.Play(0, BufferPlayFlags.Default);
  end;

procedure c_sound.stop;
  begin
    Dsbuffer.Stop;
  end;

procedure c_sound.dispose;
  begin
    Dsbuffer.Dispose;
  end;

procedure c_sound.entendre(_bool: Boolean);
  begin
    actif := _bool;
  end;

end.
